import datetime
import pymysql
'''
    定时任务：不要运行，已经在Linux部署了定时任务
    用户用于追踪更新用户注册数
'''
# 当前日期
now_date = datetime.datetime.now().strftime('%Y-%m-%d')
# 昨天日期
yesterday = (datetime.datetime.now()-datetime.timedelta(days=1)).strftime('%Y-%m-%d')
# 连接数据库
connect = pymysql.connect(host="ye-data0.mysql.rds.aliyuncs.com", user="ye_data", password="Ye7187jq",
                          port=6666, database="job_data")
cursor = connect.cursor()
# 获取当前用户数
cursor.execute("select count(*) from `user`")
now_count = cursor.fetchone()[0]
# 获取昨天用户数
cursor.execute("select sum_count from `user_monitor` where now_date = %s", (yesterday,))
yesterday_count = cursor.fetchone()[0]
# 插入新数据
cursor.execute("insert into user_monitor values(%s, %s, %s)", (now_date, int(now_count-yesterday_count), now_count))
# 提交
connect.commit()




